#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
struct student
{
	int order;
	char name[30];
};
struct node
{
	struct student data;
	struct node* next;
};
typedef struct linkqueue
{
	struct node* front;
	struct node* rear;
}lq;
lq* queueinit()
{
	lq* pq = (lq*)malloc(sizeof(lq));
	if (pq == NULL)
	{
		return NULL;
	}
	pq->front = pq->rear = NULL;
	return pq;
}
bool is_empty(lq* pq)
{
	if (pq->front == NULL && pq->rear == NULL)
		return true;
	else
		return false;
}
bool enqueue(lq* pq, int o, char* n)
{
	struct node* newnode = (struct node*)malloc(sizeof(struct node));
	if (newnode == NULL)
	{
		printf("mallo fail");
		return false;
	}
	newnode->data.order = o;
	strcpy(newnode->data.name, n);
	newnode->next = NULL;
	if (is_empty(pq))
	{
		pq->front = pq->rear = newnode;
	}
	else
	{
		pq->rear->next = newnode;
		pq->rear = newnode;
	}
	return true;
}
bool outqueue(lq* pq, struct student* val)
{
	if (is_empty(pq))
		return false;
	*val = pq->front->data;
	struct node* tmp = pq->front->next;
	pq->front->next = NULL;
	free(pq->front);
	pq->front = tmp;
	if (pq->front == NULL)
		pq->rear = pq->front;
	return true;
}
void show(lq* pq)
{
	if (is_empty(pq))
		return;
	struct node* tmp = pq->front;
	while (tmp != pq->rear)
	{
		printf("num:%d name:%s", tmp->data.order, tmp->data.name);
		tmp = tmp->next;
	}
	printf("num:%d name:%s", pq->rear->data.order, pq->rear->data.name);
}
void destory(lq* pq)
{
	if (is_empty(pq))
		return;
	struct node* tmp = pq->front;
	struct node* q = pq->front->next;
	while (tmp != pq->rear)
	{
		free(tmp);
		tmp = q;
		q = q->next;
	}
	free(pq->rear);
	pq->front = pq->rear = NULL;
}
int main()
{
	int order = 0;
	struct student c;
	int num = 0;
	char name[30] = { 0 };
	struct linkqueue* pq = queueinit();
	while (1)
	{
		printf("1 2 3 4");
		scanf("%d", &num);
		switch (num)
		{
		case 1:
			printf("qing shu ru name");
			scanf("%s", name);
			enqueue(pq, ++order, name);
			break;
		case 2:
			outqueue(pq, &c);
			printf("num:%d name:%s", c.order, c.name);
			break;
		case 3:
			show(pq);
			break;
		case 4:
			destory(pq);
			order = 0;
			break;
		default:
			break;
		}
	}
	return 0;
}